﻿#ifndef HNRJITMARQUEE_H
#define HNRJITMARQUEE_H

#include "HnrjitControl.h"

class DIRECTUI_API CHnrjitMarquee : public CHnrjitControl
{
public:
	enum AppearMode
	{
		kDefault, // 自动开启
		kAlways, // 总是开启
	};

	typedef CHnrjitMarquee::AppearMode AppearMode;

public:
	explicit CHnrjitMarquee();
	virtual ~CHnrjitMarquee();

	/// <summary>获取当前类标识</summary>
	virtual DWORD GetClsid() const { return CLSID_HNRJITMARQUEE; }

	/// <summary>设置属性值</summary>
	/// <param name="pxElement">XML元素</param>
	virtual void SetAttribute(const TiXmlElement* pxElement, HZIP hZipRes = NULL);

public:
	virtual void SetTitle(const TCHAR* pszTitle);
	virtual void SetTextAlign(UINT nTextAlign);

	AppearMode GetMode() const;
	void SetMode(AppearMode iAppearMode);

	/// <summary>获取或设置跑马灯移动时间间隔</summary>
	UINT GetInterval() const;
	void SetInterval(UINT nInterval);

	/// <summary>获取或设置跑马灯水平移动像素</summary>
	UINT GetStep() const;
	void SetStep(UINT nStep);

private:
	/// <summary>激活跑马灯线程</summary>
	void ActivateMarquee();

	/// <summary>跑马灯线程处理函数</summary>
	/// <returns>线程返回值</returns>
	virtual DWORD MarqueeThreadProc();

	static DWORD MarqueeThreadProc(void* lpParam);

public:
	// 绘制界面
	virtual void DrawControl(HDC hdc);

private:
	HANDLE m_hThread; // 跑马灯线程句柄
	HANDLE m_hQuitEvent; // 跑马灯退出事件
	HANDLE m_hResetEvent; // 跑马灯重置事件
	CRITICAL_SECTION m_csSynch; // 跑马灯同步临界区

	UINT m_nInterval; // 跑马灯移动时间间隔
	UINT m_nStep; // 跑马灯水平移动像素
	LONG m_lPosition; // 跑马灯当前位置
	LONG m_lWidth; // 文本内容实际宽度

	AppearMode m_iAppearMode; // 跑马灯状态
};

#endif // HNRJITMARQUEE_H